﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwKnjizenjeIspisProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwKnjizenjeIspisProviderBaseCore : EntityViewProviderBase<VwKnjizenjeIspis>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwKnjizenjeIspis&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwKnjizenjeIspis&gt;"/></returns>
		protected static VList&lt;VwKnjizenjeIspis&gt; Fill(DataSet dataSet, VList<VwKnjizenjeIspis> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwKnjizenjeIspis>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwKnjizenjeIspis&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwKnjizenjeIspis>"/></returns>
		protected static VList&lt;VwKnjizenjeIspis&gt; Fill(DataTable dataTable, VList<VwKnjizenjeIspis> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwKnjizenjeIspis c = new VwKnjizenjeIspis();
					c.IDKnjiz = (Convert.IsDBNull(row["IDKnjiz"]))?(int)0:(System.Int32)row["IDKnjiz"];
					c.IDKnjizStavke = (Convert.IsDBNull(row["IDKnjizStavke"]))?(int)0:(System.Int32)row["IDKnjizStavke"];
					c.PrikaznoIme = (Convert.IsDBNull(row["PrikaznoIme"]))?string.Empty:(System.String)row["PrikaznoIme"];
					c.DatumKnjizenja = (Convert.IsDBNull(row["DatumKnjizenja"]))?DateTime.MinValue:(System.DateTime)row["DatumKnjizenja"];
					c.VK = (Convert.IsDBNull(row["VK"]))?string.Empty:(System.String)row["VK"];
					c.Nalog = (Convert.IsDBNull(row["Nalog"]))?string.Empty:(System.String)row["Nalog"];
					c.Konto = (Convert.IsDBNull(row["Konto"]))?string.Empty:(System.String)row["Konto"];
					c.MT = (Convert.IsDBNull(row["MT"]))?string.Empty:(System.String)row["MT"];
					c.BrDok = (Convert.IsDBNull(row["BrDok"]))?string.Empty:(System.String)row["BrDok"];
					c.DatumDok = (Convert.IsDBNull(row["DatumDok"]))?DateTime.MinValue:(System.DateTime)row["DatumDok"];
					c.Dug = (Convert.IsDBNull(row["Dug"]))?0:(System.Decimal)row["Dug"];
					c.Pot = (Convert.IsDBNull(row["Pot"]))?0:(System.Decimal)row["Pot"];
					c.Opis = (Convert.IsDBNull(row["Opis"]))?string.Empty:(System.String)row["Opis"];
					c.Klijent = (Convert.IsDBNull(row["Klijent"]))?string.Empty:(System.String)row["Klijent"];
					c.PK = (Convert.IsDBNull(row["PK"]))?(int)0:(System.Int32)row["PK"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwKnjizenjeIspis&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwKnjizenjeIspis&gt;"/></returns>
		protected VList<VwKnjizenjeIspis> Fill(IDataReader reader, VList<VwKnjizenjeIspis> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwKnjizenjeIspis entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwKnjizenjeIspis>("VwKnjizenjeIspis",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwKnjizenjeIspis();
					}
					entity.IDKnjiz = (System.Int32)reader["IDKnjiz"];
					//entity.IDKnjiz = (Convert.IsDBNull(reader["IDKnjiz"]))?(int)0:(System.Int32)reader["IDKnjiz"];
					entity.IDKnjizStavke = (System.Int32)reader["IDKnjizStavke"];
					//entity.IDKnjizStavke = (Convert.IsDBNull(reader["IDKnjizStavke"]))?(int)0:(System.Int32)reader["IDKnjizStavke"];
					entity.PrikaznoIme = (System.String)reader["PrikaznoIme"];
					//entity.PrikaznoIme = (Convert.IsDBNull(reader["PrikaznoIme"]))?string.Empty:(System.String)reader["PrikaznoIme"];
					entity.DatumKnjizenja = (System.DateTime)reader["DatumKnjizenja"];
					//entity.DatumKnjizenja = (Convert.IsDBNull(reader["DatumKnjizenja"]))?DateTime.MinValue:(System.DateTime)reader["DatumKnjizenja"];
					entity.VK = (System.String)reader["VK"];
					//entity.VK = (Convert.IsDBNull(reader["VK"]))?string.Empty:(System.String)reader["VK"];
					entity.Nalog = (System.String)reader["Nalog"];
					//entity.Nalog = (Convert.IsDBNull(reader["Nalog"]))?string.Empty:(System.String)reader["Nalog"];
					entity.Konto = (System.String)reader["Konto"];
					//entity.Konto = (Convert.IsDBNull(reader["Konto"]))?string.Empty:(System.String)reader["Konto"];
					entity.MT = (System.String)reader["MT"];
					//entity.MT = (Convert.IsDBNull(reader["MT"]))?string.Empty:(System.String)reader["MT"];
					entity.BrDok = reader.IsDBNull(reader.GetOrdinal("BrDok")) ? null : (System.String)reader["BrDok"];
					//entity.BrDok = (Convert.IsDBNull(reader["BrDok"]))?string.Empty:(System.String)reader["BrDok"];
					entity.DatumDok = (System.DateTime)reader["DatumDok"];
					//entity.DatumDok = (Convert.IsDBNull(reader["DatumDok"]))?DateTime.MinValue:(System.DateTime)reader["DatumDok"];
					entity.Dug = (System.Decimal)reader["Dug"];
					//entity.Dug = (Convert.IsDBNull(reader["Dug"]))?0:(System.Decimal)reader["Dug"];
					entity.Pot = (System.Decimal)reader["Pot"];
					//entity.Pot = (Convert.IsDBNull(reader["Pot"]))?0:(System.Decimal)reader["Pot"];
					entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
					//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
					entity.Klijent = reader.IsDBNull(reader.GetOrdinal("Klijent")) ? null : (System.String)reader["Klijent"];
					//entity.Klijent = (Convert.IsDBNull(reader["Klijent"]))?string.Empty:(System.String)reader["Klijent"];
					entity.PK = (System.Int32)reader["PK"];
					//entity.PK = (Convert.IsDBNull(reader["PK"]))?(int)0:(System.Int32)reader["PK"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwKnjizenjeIspis"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwKnjizenjeIspis"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwKnjizenjeIspis entity)
		{
			reader.Read();
			entity.IDKnjiz = (System.Int32)reader["IDKnjiz"];
			//entity.IDKnjiz = (Convert.IsDBNull(reader["IDKnjiz"]))?(int)0:(System.Int32)reader["IDKnjiz"];
			entity.IDKnjizStavke = (System.Int32)reader["IDKnjizStavke"];
			//entity.IDKnjizStavke = (Convert.IsDBNull(reader["IDKnjizStavke"]))?(int)0:(System.Int32)reader["IDKnjizStavke"];
			entity.PrikaznoIme = (System.String)reader["PrikaznoIme"];
			//entity.PrikaznoIme = (Convert.IsDBNull(reader["PrikaznoIme"]))?string.Empty:(System.String)reader["PrikaznoIme"];
			entity.DatumKnjizenja = (System.DateTime)reader["DatumKnjizenja"];
			//entity.DatumKnjizenja = (Convert.IsDBNull(reader["DatumKnjizenja"]))?DateTime.MinValue:(System.DateTime)reader["DatumKnjizenja"];
			entity.VK = (System.String)reader["VK"];
			//entity.VK = (Convert.IsDBNull(reader["VK"]))?string.Empty:(System.String)reader["VK"];
			entity.Nalog = (System.String)reader["Nalog"];
			//entity.Nalog = (Convert.IsDBNull(reader["Nalog"]))?string.Empty:(System.String)reader["Nalog"];
			entity.Konto = (System.String)reader["Konto"];
			//entity.Konto = (Convert.IsDBNull(reader["Konto"]))?string.Empty:(System.String)reader["Konto"];
			entity.MT = (System.String)reader["MT"];
			//entity.MT = (Convert.IsDBNull(reader["MT"]))?string.Empty:(System.String)reader["MT"];
			entity.BrDok = reader.IsDBNull(reader.GetOrdinal("BrDok")) ? null : (System.String)reader["BrDok"];
			//entity.BrDok = (Convert.IsDBNull(reader["BrDok"]))?string.Empty:(System.String)reader["BrDok"];
			entity.DatumDok = (System.DateTime)reader["DatumDok"];
			//entity.DatumDok = (Convert.IsDBNull(reader["DatumDok"]))?DateTime.MinValue:(System.DateTime)reader["DatumDok"];
			entity.Dug = (System.Decimal)reader["Dug"];
			//entity.Dug = (Convert.IsDBNull(reader["Dug"]))?0:(System.Decimal)reader["Dug"];
			entity.Pot = (System.Decimal)reader["Pot"];
			//entity.Pot = (Convert.IsDBNull(reader["Pot"]))?0:(System.Decimal)reader["Pot"];
			entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
			//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
			entity.Klijent = reader.IsDBNull(reader.GetOrdinal("Klijent")) ? null : (System.String)reader["Klijent"];
			//entity.Klijent = (Convert.IsDBNull(reader["Klijent"]))?string.Empty:(System.String)reader["Klijent"];
			entity.PK = (System.Int32)reader["PK"];
			//entity.PK = (Convert.IsDBNull(reader["PK"]))?(int)0:(System.Int32)reader["PK"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwKnjizenjeIspis"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwKnjizenjeIspis"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwKnjizenjeIspis entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDKnjiz = (Convert.IsDBNull(dataRow["IDKnjiz"]))?(int)0:(System.Int32)dataRow["IDKnjiz"];
			entity.IDKnjizStavke = (Convert.IsDBNull(dataRow["IDKnjizStavke"]))?(int)0:(System.Int32)dataRow["IDKnjizStavke"];
			entity.PrikaznoIme = (Convert.IsDBNull(dataRow["PrikaznoIme"]))?string.Empty:(System.String)dataRow["PrikaznoIme"];
			entity.DatumKnjizenja = (Convert.IsDBNull(dataRow["DatumKnjizenja"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumKnjizenja"];
			entity.VK = (Convert.IsDBNull(dataRow["VK"]))?string.Empty:(System.String)dataRow["VK"];
			entity.Nalog = (Convert.IsDBNull(dataRow["Nalog"]))?string.Empty:(System.String)dataRow["Nalog"];
			entity.Konto = (Convert.IsDBNull(dataRow["Konto"]))?string.Empty:(System.String)dataRow["Konto"];
			entity.MT = (Convert.IsDBNull(dataRow["MT"]))?string.Empty:(System.String)dataRow["MT"];
			entity.BrDok = (Convert.IsDBNull(dataRow["BrDok"]))?string.Empty:(System.String)dataRow["BrDok"];
			entity.DatumDok = (Convert.IsDBNull(dataRow["DatumDok"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumDok"];
			entity.Dug = (Convert.IsDBNull(dataRow["Dug"]))?0:(System.Decimal)dataRow["Dug"];
			entity.Pot = (Convert.IsDBNull(dataRow["Pot"]))?0:(System.Decimal)dataRow["Pot"];
			entity.Opis = (Convert.IsDBNull(dataRow["Opis"]))?string.Empty:(System.String)dataRow["Opis"];
			entity.Klijent = (Convert.IsDBNull(dataRow["Klijent"]))?string.Empty:(System.String)dataRow["Klijent"];
			entity.PK = (Convert.IsDBNull(dataRow["PK"]))?(int)0:(System.Int32)dataRow["PK"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwKnjizenjeIspisFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwKnjizenjeIspis"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwKnjizenjeIspisFilterBuilder : SqlFilterBuilder<VwKnjizenjeIspisColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwKnjizenjeIspisFilterBuilder class.
		/// </summary>
		public VwKnjizenjeIspisFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwKnjizenjeIspisFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwKnjizenjeIspisFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwKnjizenjeIspisFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwKnjizenjeIspisFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwKnjizenjeIspisFilterBuilder

	#region VwKnjizenjeIspisParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwKnjizenjeIspis"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwKnjizenjeIspisParameterBuilder : ParameterizedSqlFilterBuilder<VwKnjizenjeIspisColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwKnjizenjeIspisParameterBuilder class.
		/// </summary>
		public VwKnjizenjeIspisParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwKnjizenjeIspisParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwKnjizenjeIspisParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwKnjizenjeIspisParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwKnjizenjeIspisParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwKnjizenjeIspisParameterBuilder
} // end namespace
